#encoding: utf-8
'''
Created on 2012-9-1

@author: zhangtj
'''
import MySQLdb
from django.utils import timezone
from datetime import datetime


"""
向数据库中的用户表中插入用户数据
"""
def generateUserData(cursor):
    for i in range(1000):
        username = 'test' + str(i)
        psw = '123456'
        type = '1'
        email = 'test' + str(i) + '@gmail.com'
        sq = "test safequestion"
        sa = "test safeanswer"
        sex = 'man'
        cursor.execute("INSERT INTO szdb_user values(%s, %s, %s, %s, %s, %s, %s)",\
                       (username, psw, type, email, sq, sa, sex))
    cursor.close()


"""
生成活动数据
"""    
def generateActivity(cursor):
    for i in range(1000):
        username = 'test' + str(i)
        title = "环球旅行"+ str(i)
        content = "我们一起去环球旅行"+str(i)
        releasetime = datetime.now()
        date = datetime.now()
        ownid = username
        place = "玻利维亚" + str(i)
        cursor.execute("INSERT INTO szdb_activity values( %s ,%s, %s, %s, %s, %s, %s)",\
                       (None,title, content, str(releasetime), str(date), str(ownid), str(place)))

if __name__ == '__main__':
    conn=MySQLdb.connect(host="localhost" , port=3306,user="root",passwd="916883",db="szyddb",charset="utf8")
    cursor=conn.cursor()
#    generateUserData(cursor)
    generateActivity(cursor)
    conn.commit()
    conn.close()
